﻿@using ST = EmoneyWeiXinCommon.StringTools;
@using EmoneyWeiXinEntity;
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "二维码统计";
}
<div class="right">
    <h3>二维码统计</h3>
    <!--manage-->
    <div class="manage">
        <!--manage_top-->
        <div class="manage_top">
            <div class="manage_top">
                <ul class="manage_top_ul">
                </ul>
            </div>
            <div class="manage_register">
                <p id="pType">
                </p>
                <p><span>参数值：</span><input id="txtVal" type="text"></p>
            </div>
            <p class="manage_add">
                <a id="btnQuery">查询</a>
            </p>
        </div>
        <!--manage_top end-->
        <p class="manage_line"></p>
        <!--manage_bottom-->
        <div class="manage_bottom">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th><span>编号</span></th>
                    <th><span>二维码分类</span></th>
                    <th><span>二维码参数</span></th>
                    <th><span>二维码名称</span></th>
                    <th><span>关注数</span></th>
                    <th><span>取消数</span></th>
                    <th><span>操作</span></th>
                </tr>
                <tbody id="dvList">
                </tbody>

            </table>
            <div class="manage_page" id="manage_page">
            </div>
        </div>
        <!--manage_bottom end-->
    </div>
    <!--manage end-->
</div>

<script type="text/javascript">
    var weixinid = "";
    var pageIndex = 1;
    var pageSize = 10;
    var pageCount = 1;
    var totalCount = 0;
    $(document).ready(function () {
        createMemu();
        //查询
        $("#btnQuery").click(function () {
            if (ischeck())
                pageIndex = 1;
            gotoPage();
        });
    });
    function getContentMemu() {
        $(".manage_top_ul .manage_top_A").each(function () {
            weixinid = $(this).attr("typeid");
        })
        if (weixinid > 0) {
            bindtype(function (result) {
                if (result == "1") {
                    gotoPage();
                }
            });
        }
    }

    //创建labs
    function createMemu() {
        $.ajax({
            type: "get",
            url: "@ST.GetTrendsFile("BaseConfiguration/WeixinUserMemu")" + "?random=" + Math.random(),
            async: true,
            data: { weixinid: "@ViewBag.weixinid" },
            dataType: "html",
            success: function (result) {
                $(".manage_top_ul").html(result);
                $(".manage_top_ul li").click(function () {
                    $(".manage_top_ul li").removeClass("manage_top_A");
                    $(this).addClass("manage_top_A");
                    reseting();
                    getContentMemu();
                })
                getContentMemu();
            }
        })
    }
    var ajaxdata = {};
    function gotoPage() {
        ajaxdata["weixinid"] = weixinid;
        ajaxdata["index"] = pageIndex;
        ajaxdata["size"] = pageSize;
        ajaxdata["type"] = $("#drpType").val();
        ajaxdata["value"] = $("#txtVal").val();
        $.ajax({
            url: "@ST.GetTrendsFile("TwoCode/GetTwoCodeStatList")",
            type: "POST",
            async: true,
            data: ajaxdata,
            beforeSend: function () {
                //showLoading();
            },
            complete: function () {
                //iddenLoading();
            },
            success: function (result) {
                if (result != "" && result != null && result != undefined) {
                    var arrData = result.split("~");
                    totalCount = arrData[0];
                    var data = arrData[1];
                    var d = eval(data);
                    var html = "";
                    for (var i = 0; i < d.length; i++) {
                        html += "<tr>";
                        html += getTxtTd(d[i]["rowid"]) + getTxtTd(d[i]["typename"]) + getTxtTd(d[i]["value"]);
                        html += getTxtTd(d[i]["keyname"]) + getTxtTd(d[i]["createnum"]) + getTxtTd(d[i]["cancelnum"]) + getXqTd(d[i]["value"], d[i]["keyname"], d[i]["updatetime"].replace(/T/g, " "), weixinid);
                        html += "</tr>";
                    }

                    $("#dvList").html(html);
                    PageCountHtml();
                } else {
                    $("#dvList").html("没有查询到相关数据!");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert(errorThrown);
            }
        });
    }
    function getTxtTd(s) {
        return '<td><span>' + s + '</span></td>';
    }
    function getXqTd(value, name, date, weixinid) {
        value = encodeURI(value);
        name = encodeURI(name);
        date = encodeURI(date);
        weixinid = encodeURI(weixinid);
        var hrefvalue = "@ST.GetTrendsFile("TwoCode/TwoCodeStatDetail")" + "?value=" + value + "&name=" + name + "&date=" + date + "&weixinid=" + weixinid + "&leftid=@ViewBag.leftid";
        return '<td><a href="' + hrefvalue + '" class="red manage_bottom_a">查看详情</a></td>';
    }
    function reseting() {
        $("#drpType").val("0");
        $("#txtVal").val("");
    }
    function ischeck() {
        var drpType = $("#drpType").val();
        if (drpType == "") {
            alert("分类不能空！");
            $("#drpType").focus();
            return false;
        }
        var txtValue = $("#txtValue").val();
        if (txtValue == "")
        { alert("参数值不能空，请重新输入！"); $("#txtValue").focus(); return false; }
        var value = 0;
        try {
            value = parseInt(txtValue);
        }
        catch (err) {
            alert("参数值格式不正确，请重新输入！"); $("#txtValue").focus(); return false;
        }
        return true;
    }

    function PageCountHtml() {
        pageCount = Math.ceil(totalCount / pageSize);
        if (pageCount == 0) {
            pageCount = 1;
        }
        $("#manage_page").html(PageHtml(pageIndex, pageCount));
        $("#manage_page .manage_page_right").click(function () {
            pageIndex = parseInt($("#txtPageNum").val()) + parseInt($(this).attr("tname"));
            $("#manage_page").html(PageHtml(pageIndex, pageCount));
            gotoPage();
        });
        $("#manage_page .tiaozhuan").click(function () {
            var pageNum = $("#txtPageNum").val();
            try {
                pageIndex = parseInt(pageNum);
            } catch (e) {
                alert("请输入数字");
                return false;
            }

            if (pageNum > 0 && pageNum <= pageCount) {
                $("#manage_page").html(PageHtml(pageIndex, pageCount));
                gotoPage();
            }
            else {
                alert("当前数字超出范围");
                return false;
            }
        });
    }
    function bindtype(fn) {
        $.ajax({
            url: "@ST.GetTrendsFile("TwoCode/GetTwoCodeType")",
            type: "POST",
            async: true,
            data: { weixinid: weixinid },
            beforeSend: function () {
                //showLoading();
            },
            complete: function () {
                // hiddenLoading();
            },
            success: function (data) {
                if (data != null && data != "" && data != undefined) {
                    var d = eval(data);
                    $("#pType").html("");
                    var html = '<span>分类：</span><select id="drpType" ><option value="0">全部</option>';
                    for (var i = 0; i < d.length; i++) {
                        html += ' <option value="' + d[i]["ID"] + '">' + d[i]["name"] + '</option>';
                    }
                    html += '</select>';
                    $("#pType").append(html);
                    fn('1');
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert(errorThrown);
            }
        });
        //翻页

    }
</script>

